package com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.xml.internal.ws.util.xml.CDATA;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.entity.DmDsSource;

import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.entity.DmDsSourceEnum;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.mapper.DmDsSourceMapper;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.model.params.DmDsSourceParam;
import com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.service.DmDsSourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.xnewtech.xplatform.swan.dataSourceManage.modular.modname.entity.DmDsSourceEnum.*;
import static org.apache.ibatis.ognl.DynamicSubscript.all;

/**
 * (DmDsSource)表服务实现类
 *
 * @author makejava
 * @since 2021-09-22 13:19:39
 */
@Service
public class DmDsSourceServiceImpl extends ServiceImpl<DmDsSourceMapper, DmDsSource> implements DmDsSourceService {

    @Resource
    private DmDsSourceMapper dmDsSourceMapper;

    /**
     * 新增数据
     *
     * @param dmDsSource 实例对象
     * @return 实例对象
     */
    @Override
    public DmDsSource insert(DmDsSource dmDsSource) {
        this.dmDsSourceMapper.insert(dmDsSource);
        return dmDsSource;
    }

    /**
     * 删除数据
     *
     * @param id 对象id
     */
    @Override
    public void deleteById (Long id){
        this.dmDsSourceMapper.deleteById(id);
    }

    /**
     * 修改数据
     *
     * @param umDsSource 实例对象
     * @return 实例对象
     */
    @Override
    public DmDsSource update(DmDsSource umDsSource) {
        this.dmDsSourceMapper.update(umDsSource);
        return umDsSource;
    }

    /**
     * 查询数据源
     *
     * @param dataType  数据源类型
     * @param dsName    数据源名称
     * @param pageNum   分页数
     * @param pageSize  分页大小
     * @return DmDsSource
     */
    @Override
    public List<Map<DmDsSource,DmDsSource> > select(DmDsSourceEnum dataType, String dsName, Integer pageNum, Integer pageSize) {
        if (pageNum<1){
            pageNum =0;
        } else {
            pageNum = (pageNum-1)*pageSize;
        }

        if (dataType.equals(All)) {
            return dmDsSourceMapper.select(null, dsName, pageNum, pageSize);
        } else {
            return dmDsSourceMapper.select(dataType, dsName, pageNum, pageSize);
        }
    }

    /**
     * 通过dsId批量删除数据源
     * @param dsId 多个dsId
     */
    @Override
    public Integer batchDelete(Integer[] dsId){
        return dmDsSourceMapper.batchDelete(dsId);
    }


}
